package com.gzc.just.play.last.war.centralserver.guild.repository;



import com.gzc.just.play.last.war.centralserver.guild.model.GuildMember;

import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.data.jpa.repository.Query;

import org.springframework.data.repository.query.Param;

import org.springframework.stereotype.Repository;



import java.util.List;

import java.util.Optional;



@Repository

public interface GuildMemberRepository extends JpaRepository<GuildMember, Long> {

    

    Optional<GuildMember> findByPlayerId(Long playerId);

    

    List<GuildMember> findByGuildId(Long guildId);

    

    List<GuildMember> findByGuildIdAndRole(Long guildId, GuildMember.Role role);

    

    @Query("SELECT COUNT(gm) FROM GuildMember gm WHERE gm.guildId = :guildId")

    int countByGuildId(@Param("guildId") Long guildId);

    

    @Query("SELECT gm FROM GuildMember gm WHERE gm.guildId = :guildId ORDER BY gm.role DESC, gm.joinTime ASC")

    List<GuildMember> findByGuildIdOrderByRole(@Param("guildId") Long guildId);

}

